<template>
  <div class="tabbar">
    <div 
      class="tab-item" 
      v-for="item in tabs" 
      :key="item.path"
      :class="{ active: isActive(item.path) }"
      @click="navigateTo(item.path)"
    >
      <div class="tab-icon">{{ item.icon }}</div>
      <div class="tab-text">{{ item.text }}</div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useRouter, useRoute } from 'vue-router'
import { computed } from 'vue'

const router = useRouter()
const route = useRoute()

const tabs = [
  {
    path: '/',
    text: '首页',
    icon: '🏠'
  },
  {
    path: '/category',
    text: '分类',
    icon: '📂'
  },
  {
    path: '/cart',
    text: '购物车',
    icon: '🛒'
  },
  {
    path: '/user',
    text: '我的',
    icon: '👤'
  }
]

const isActive = (path: string) => {
  if (path === '/') {
    return route.path === '/'
  }
  return route.path.startsWith(path)
}

const navigateTo = (path: string) => {
  router.push(path)
}
</script>

<style scoped>
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: #fff;
  border-top: 1px solid #e5e5e5;
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 1000;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  cursor: pointer;
  transition: all 0.3s ease;
}

.tab-item:hover {
  background-color: #f5f5f5;
}

.tab-item.active {
  color: #007aff;
}

.tab-item.active .tab-icon {
  transform: scale(1.1);
}

.tab-icon {
  font-size: 20px;
  margin-bottom: 4px;
  transition: transform 0.3s ease;
}

.tab-text {
  font-size: 12px;
  font-weight: 500;
}

/* 为有TabBar的页面添加底部间距 */
.page-with-tabbar {
  padding-bottom: 60px;
}
</style> 